/**
 * Filename: UesrAlbumStatusAdapter.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/3/6 15:05
 */
package com.github.postsanf.yinian.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.activity.BrowseActivity;
import com.github.postsanf.yinian.activity.MemoryCardDetailActivity;
import com.github.postsanf.yinian.activity.MemoryCardDetailCommentActivity;
import com.github.postsanf.yinian.activity.StatusDetailActivity;
import com.github.postsanf.yinian.bean.YNStatus;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.github.postsanf.yinian.constants.CommonConstants;
import com.github.postsanf.yinian.utils.UIHelper;
import com.github.postsanf.yinian.constants.YNSingleton;
import com.github.postsanf.yinian.utils.DisplayUtils;
import com.github.postsanf.yinian.utils.ImageOptHelper;
import com.github.postsanf.yinian.utils.StringUtils;
import com.github.postsanf.yinian.utils.TimeUtils;
import com.github.postsanf.yinian.utils.YNUrlHelper;
import com.github.postsanf.yinian.widget.RotateAnimation;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

public class UesrAlbumStatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<YNStatus> mDatas;
    private OnItemClickListener mListener;
    private boolean isInAlbum = false;
    private boolean aIsMe = false;
    private static final int EMPTY_VIEW = 10;
    private HashMap<Integer, String> datemap;
    private HashMap<Integer, Boolean> yearmap;
    int nowyytime = 0;
    int nowyear = 0;
    private boolean enableRefresh;
    private int userid;

    public List<YNStatus> getDatas() {
        return mDatas;
    }

    public void setDatas(List<YNStatus> datas) {
        mDatas = datas;
    }

    public boolean isInAlbum() {
        return isInAlbum;
    }

    public void setIsInAlbum(boolean isInAlbum) {
        this.isInAlbum = isInAlbum;
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    public UesrAlbumStatusAdapter(Context context, List<YNStatus> mDatas, boolean aIsMe, int userid) {
        this.context = context;
        this.mDatas = mDatas;
        this.aIsMe = aIsMe;
        this.userid = userid;
        datemap = new HashMap<>();
        yearmap = new HashMap<>();
    }

    public class EmptyViewHolder extends RecyclerView.ViewHolder {
        public EmptyViewHolder(View itemView) {
            super(itemView);
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private final TextView view_time_day;
        private final ImageView view_time_whiteblack;
        private final RelativeLayout rl_day_sign;
        private final LinearLayout ll_day_sign;
        private final ImageView iv_day_sign;
        private final LinearLayout ll_gridview;
        private final LinearLayout ll_item;
        GridView mGridView;
        View line1;
        View line2;
        TextView item_tt;
        TextView item_comment_num;
        TextView item_etext;
        LinearLayout ll_status_comment;
        LinearLayout view_time;
        //        TextView view_time_mouth;
//        TextView view_time_year;
        ImageView item_memorycardpic;
        TextView item_memorytime;
        TextView item_memorylocation;
        RelativeLayout item_memorycard;

        RelativeLayout item_timecard_reversal;
        LinearLayout item_timecard_reversal_cover;
        ImageView item_timecardpic;
        TextView tv_timecard_comment_number;
        ImageView item_timecard_share;
        LinearLayout item_timecard_comment;

        LinearLayout item_time_card_reversal_back;
        ImageView item_timecardpic_back;
        ImageView item_timecard_mic_iv;
        TextView item_timecard_mic_tx;
        TextView item_timecard_from_content;

        public ViewHolder(View itemView) {
            super(itemView);
            mGridView = (GridView) itemView.findViewById(R.id.item_gridview);
            line1 = (View) itemView.findViewById(R.id.view_1);
            line2 = (View) itemView.findViewById(R.id.view_2);
            ll_item = ((LinearLayout) itemView.findViewById(R.id.ll_item));
            item_tt = (TextView) itemView.findViewById(R.id.item_tt);
            item_etext = (TextView) itemView.findViewById(R.id.item_etext);
            item_memorycard = (RelativeLayout) itemView.findViewById(R.id.item_memorycard);
            item_memorycardpic = (ImageView) itemView.findViewById(R.id.item_memorycardpic);
            item_memorytime = (TextView) itemView.findViewById(R.id.item_memorytime);
            item_memorylocation = (TextView) itemView.findViewById(R.id.item_memorylocation);
            ll_status_comment = (LinearLayout) itemView.findViewById(R.id.ll_status_comment);
            item_comment_num = (TextView) itemView.findViewById(R.id.tv_comment_number);
            view_time = (LinearLayout) itemView.findViewById(R.id.view_time);
//            view_time_mouth = (TextView) itemView.findViewById(R.id.view_time_mouth);
//            view_time_year = (TextView) itemView.findViewById(R.id.view_time_year);
            view_time_day = ((TextView) itemView.findViewById(R.id.view_time_day));
            view_time_whiteblack = ((ImageView) itemView.findViewById(R.id.view_time_whiteblack));

            item_timecard_reversal = (RelativeLayout) itemView.findViewById(R.id.item_timecard_reversal);
            item_timecard_reversal_cover = (LinearLayout) itemView.findViewById(R.id.item_timecard_reversal_cover);
            item_timecardpic = (ImageView) itemView.findViewById(R.id.item_timecardpic);
            item_timecard_share = (ImageView) itemView.findViewById(R.id.item_timecard_share);
            item_timecard_comment = (LinearLayout) itemView.findViewById(R.id.item_timecard_comment);
            tv_timecard_comment_number = (TextView) itemView.findViewById(R.id.tv_timecard_comment_number);

            item_time_card_reversal_back = (LinearLayout) itemView.findViewById(R.id.item_time_card_reversal_back);
            item_timecardpic_back = (ImageView) itemView.findViewById(R.id.item_timecardpic_back);
            item_timecard_mic_iv = (ImageView) itemView.findViewById(R.id.item_timecard_mic_iv);
            item_timecard_mic_tx = (TextView) itemView.findViewById(R.id.item_timecard_mic_tx);

            item_timecard_from_content = (TextView) itemView.findViewById(R.id.item_timecard_from_content);

            //日签
            rl_day_sign = ((RelativeLayout) itemView.findViewById(R.id.rl_day_sign));
            ll_day_sign = ((LinearLayout) itemView.findViewById(R.id.ll_day_sign));
            iv_day_sign = ((ImageView) itemView.findViewById(R.id.iv_day_sign));
            ll_gridview = ((LinearLayout) itemView.findViewById(R.id.ll_gridview));
        }

        public void bindData(final YNStatus item, final int position) {
            if (item != null) {
                if (position == 0) {
                    nowyytime = 0;
                    nowyear = 0;
                }
//                List<String> sslist = item.getUrl();
                List<String> sslist = item.getThumbnail();
                List<String> sslist2 = getUrlList(sslist);
                RelativeLayout.LayoutParams lineparams = (RelativeLayout.LayoutParams) line2.getLayoutParams();
//                Log.d("yuhao", "item.getEtype()="+item.getEtype());
                if (item.getEtype() == 1) {
                    view_time_whiteblack.setImageResource(R.drawable.circle_blue);
                    lineparams.height = UIHelper.dip2px(context, 85) + UIHelper.getHigh(context) - UIHelper.dip2px(context, 12);
                    ll_gridview.setVisibility(View.GONE);
                    line2.setLayoutParams(lineparams);
                    rl_day_sign.setVisibility(View.GONE);
                    mGridView.setVisibility(View.GONE);
                    item_etext.setVisibility(View.GONE);
                    item_timecard_reversal.setVisibility(View.GONE);
                    item_memorycard.setVisibility(View.VISIBLE);
                    ll_status_comment.setVisibility(View.VISIBLE);
                    item_memorycard.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, UIHelper.getHigh(context) + UIHelper.dip2px(context, 25)));
                    String paths = YNUrlHelper.getStatusUrl(context, sslist.get(0));
//                    ImageOptHelper.showFrescoStatus(Uri.parse(StringUtils.repaceImgUrl(paths)), item_memorycardpic, context);
                    ImageOptHelper.showFrescoStatus(StringUtils.repaceImgUrl(paths), item_memorycardpic, context);
                    item_memorytime.setText("发生于" + item.getEmemorytime().split(" ")[0]);
                    if (!StringUtils.isEmpty(item.getEplace())) {
                        if (item.getEplace().length() > 8) {
                            item_memorylocation.setText(item.getEplace().substring(0, 7) + "...");
                        } else {
                            item_memorylocation.setText(item.getEplace());
                        }
                    } else {
                        item_memorylocation.setText("忆年");
                    }
                    item_memorycard.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            YNSingleton.getInstance().getCurAlbum().setGtype(" ");
                            YNSingleton.getInstance().setCurStatus(item);
                            context.startActivity(new Intent(context, MemoryCardDetailActivity.class).putExtra("lookStatus", "lookStatus").putExtra("userStatus", true));
                            context.sendBroadcast(new Intent(ACTIONs.actionLookStatus).putExtra("eid", item.getEid()));
                        }
                    });
                    ll_item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            YNSingleton.getInstance().getCurAlbum().setGtype(" ");
                            YNSingleton.getInstance().setCurStatus(item);
                            context.startActivity(new Intent(context, MemoryCardDetailActivity.class).putExtra("lookStatus", "lookStatus").putExtra("userStatus", true));
                            context.sendBroadcast(new Intent(ACTIONs.actionLookStatus).putExtra("eid", item.getEid()));
                        }
                    });
                } else if (item.getEtype() == 2) {
                    view_time_whiteblack.setImageResource(R.drawable.circle_yellow);
                    lineparams.height = UIHelper.dip2px(context, 38) + UIHelper.getMyTimeCardHigh(context) - UIHelper.dip2px(context, 16);
                    line2.setLayoutParams(lineparams);
                    ll_gridview.setVisibility(View.GONE);
                    rl_day_sign.setVisibility(View.GONE);
                    mGridView.setVisibility(View.GONE);
                    item_etext.setVisibility(View.GONE);
                    item_memorycard.setVisibility(View.GONE);
                    ll_status_comment.setVisibility(View.GONE);
                    item_timecard_reversal.setVisibility(View.VISIBLE);
                    item_timecard_reversal.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, UIHelper.getMyTimeCardHigh(context)));
                    String coverbackpath = YNUrlHelper.getCoverUrl(context, sslist.get(0));
//                    ImageOptHelper.showFrescoSingeTimeCardCover(Uri.parse(item.getEcover()), item_timecardpic, context);
//                    ImageOptHelper.showFrescoSingeTimeCardCover(Uri.parse(StringUtils.repaceImgUrl(coverbackpath)), item_timecardpic_back, context);
                    ImageOptHelper.showFrescoStatus(item.getEcover() + "?imageView2/2/w/480", item_timecardpic, context);
                    ImageOptHelper.showFrescoStatus(StringUtils.repaceImgUrl(coverbackpath), item_timecardpic_back, context);
                    if (StringUtils.isEmpty(item.getEaudio())) {
                        item_timecard_mic_tx.setText("0'00");
                        item_timecard_mic_iv.setImageResource(R.drawable.timecard_sound_no);
                    } else {
                        item_timecard_mic_tx.setText(" ");
                        item_timecard_mic_iv.setImageResource(R.drawable.timecard_detail_mic3);
                    }
                    if (!StringUtils.isEmpty(item.getEplace())) {
                        item_timecard_from_content.setText(item.getEplace());
                    }
                    item_timecard_reversal.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            YNSingleton.getInstance().getCurAlbum().setGtype(" ");
                            enableRefresh = true;
                            float cX = item_timecard_reversal.getWidth() / 2.0f;
                            float cY = item_timecard_reversal.getHeight() / 2.0f;
                            RotateAnimation rotateAnim = new RotateAnimation(cX, cY, RotateAnimation.ROTATE_INCREASE);
                            if (rotateAnim != null) {
                                rotateAnim.setInterpolatedTimeListener(new RotateAnimation.InterpolatedTimeListener() {
                                    @Override
                                    public void interpolatedTime(float interpolatedTime) {
                                        if (enableRefresh && interpolatedTime > 0.5f) {
                                            item_timecard_reversal_cover.setVisibility(View.GONE);
                                            item_time_card_reversal_back.setVisibility(View.VISIBLE);
                                            enableRefresh = false;
                                        }
                                    }
                                });
                                rotateAnim.setFillAfter(true);
                                item_timecard_reversal.startAnimation(rotateAnim);
                                rotateAnim.setAnimationListener(new Animation.AnimationListener() {
                                    @Override
                                    public void onAnimationStart(Animation animation) {
                                    }

                                    @Override
                                    public void onAnimationEnd(Animation animation) {
                                        YNSingleton.getInstance().setCurStatus(item);
                                        context.sendBroadcast(new Intent(ACTIONs.actionToTimeCardDetail));
                                        new Handler().postDelayed(new Runnable() {
                                            @Override
                                            public void run() {
                                                item_timecard_reversal_cover.setVisibility(View.VISIBLE);
                                                item_time_card_reversal_back.setVisibility(View.GONE);
                                            }
                                        }, 1300);
                                    }

                                    @Override
                                    public void onAnimationRepeat(Animation animation) {
                                    }
                                });
                            }
                        }
                    });
                    ll_item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            YNSingleton.getInstance().getCurAlbum().setGtype(" ");
                            YNSingleton.getInstance().setCurStatus(item);
                            enableRefresh = true;
                            float cX = item_timecard_reversal.getWidth() / 2.0f;
                            float cY = item_timecard_reversal.getHeight() / 2.0f;
                            RotateAnimation rotateAnim = new RotateAnimation(cX, cY, RotateAnimation.ROTATE_INCREASE);
                            if (rotateAnim != null) {
                                rotateAnim.setInterpolatedTimeListener(new RotateAnimation.InterpolatedTimeListener() {
                                    @Override
                                    public void interpolatedTime(float interpolatedTime) {
                                        if (enableRefresh && interpolatedTime > 0.5f) {
                                            item_timecard_reversal_cover.setVisibility(View.GONE);
                                            item_time_card_reversal_back.setVisibility(View.VISIBLE);
                                            enableRefresh = false;
                                        }
                                    }
                                });
                                rotateAnim.setFillAfter(true);
                                item_timecard_reversal.startAnimation(rotateAnim);
                                rotateAnim.setAnimationListener(new Animation.AnimationListener() {
                                    @Override
                                    public void onAnimationStart(Animation animation) {
                                    }

                                    @Override
                                    public void onAnimationEnd(Animation animation) {
                                        YNSingleton.getInstance().setCurStatus(item);
                                        context.sendBroadcast(new Intent(ACTIONs.actionToTimeCardDetail));
                                        context.sendBroadcast(new Intent(ACTIONs.actionLookStatus).putExtra("eid", item.getEid()));
                                        new Handler().postDelayed(new Runnable() {
                                            @Override
                                            public void run() {
                                                item_timecard_reversal_cover.setVisibility(View.VISIBLE);
                                                item_time_card_reversal_back.setVisibility(View.GONE);
                                            }
                                        }, 1300);
                                    }

                                    @Override
                                    public void onAnimationRepeat(Animation animation) {
                                    }
                                });
                            }
                        }
                    });
                } else if (item.getEtype() == 3) {
                    view_time_whiteblack.setImageResource(R.drawable.circle_blue);
                    lineparams.height = UIHelper.dip2px(context, 38) + UIHelper.getDaySignHight(context) - UIHelper.dip2px(context, 16);
                    line2.setLayoutParams(lineparams);
                    ll_gridview.setVisibility(View.GONE);
                    rl_day_sign.setVisibility(View.VISIBLE);
                    mGridView.setVisibility(View.GONE);
                    item_etext.setVisibility(View.GONE);
                    item_memorycard.setVisibility(View.GONE);
                    ll_status_comment.setVisibility(View.VISIBLE);
                    item_timecard_reversal.setVisibility(View.GONE);
                    ll_day_sign.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, UIHelper.getDaySignHight(context) - UIHelper.dip2px(context, 40)));
                    ImageOptHelper.showFrescoStatus(item.getUrl().get(0), iv_day_sign, context);
                    ll_day_sign.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            YNSingleton.getInstance().getCurAlbum().setGtype(" ");
                            YNSingleton.getInstance().setCurStatus(item);
                            Intent dsIntent = new Intent(context, BrowseActivity.class);
                            dsIntent.putExtra(CommonConstants.YNPOSITION, 0);
                            dsIntent.putExtra("isDaySign", true);
                            dsIntent.putExtra(CommonConstants.YNISME, true);
                            dsIntent.putExtra("type", "time");
                            context.startActivity(dsIntent);
                        }
                    });
                    ll_item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            YNSingleton.getInstance().getCurAlbum().setGtype(" ");
                            YNSingleton.getInstance().setCurStatus(item);
                            Intent dsIntent = new Intent(context, BrowseActivity.class);
                            dsIntent.putExtra(CommonConstants.YNPOSITION, 0);
                            dsIntent.putExtra("isDaySign", true);
                            dsIntent.putExtra(CommonConstants.YNISME, true);
                            dsIntent.putExtra("type", "time");
                            context.startActivity(dsIntent);
                        }
                    });
                } else {
                    view_time_whiteblack.setImageResource(R.drawable.circle_black);
                    ll_gridview.setVisibility(View.VISIBLE);
                    rl_day_sign.setVisibility(View.GONE);
                    if (item.getEtext() != null && !item.getEtext().equals("")) {
                        lineparams.height = UIHelper.dip2px(context, 85) + UIHelper.getHigh(context) - UIHelper.dip2px(context, 5);
                        item_etext.setVisibility(View.VISIBLE);
                        item_etext.setText(item.getEtext());
                    } else {
                        lineparams.height = UIHelper.dip2px(context, 60) + UIHelper.getHigh(context) - UIHelper.dip2px(context, 5);
                        item_etext.setVisibility(View.GONE);
                    }
                    item_timecard_reversal.setVisibility(View.GONE);
                    ll_status_comment.setVisibility(View.VISIBLE);
                    item_memorycard.setVisibility(View.GONE);
                    mGridView.setVisibility(View.VISIBLE);
                    mGridView.setAdapter(new UserGridViewAdapter(context, sslist2, sslist.size()));
                    final int gridviewsize = sslist2.size();
                    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int pindex, long l) {
                            if (gridviewsize == 3 && pindex == 2) {
                                YNSingleton.getInstance().getCurAlbum().setGtype(" ");
                                YNSingleton.getInstance().setCurStatus(item);
                                context.startActivity(new Intent(context, StatusDetailActivity.class).putExtra("lookPeople", "lookPeople").putExtra("userStatus", true));
                                context.sendBroadcast(new Intent(ACTIONs.actionLookStatus).putExtra("eid", item.getEid()));
                                return;
                            }
                            YNSingleton.getInstance().setCurStatus(item);
                            Intent intent = new Intent(context, BrowseActivity.class);
                            intent.putExtra(CommonConstants.YNPOSITION, position);
                            intent.putExtra(CommonConstants.YNISME, true);
                            intent.putExtra("type", "time");
                            context.startActivity(intent);
                        }
                    });
                    ll_item.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            YNSingleton.getInstance().getCurAlbum().setGtype(" ");
                            YNSingleton.getInstance().setCurStatus(item);
                            context.startActivity(new Intent(context, StatusDetailActivity.class).putExtra("lookPeople", "lookPeople").putExtra("userStatus", true));
                            context.sendBroadcast(new Intent(ACTIONs.actionLookStatus).putExtra("eid", item.getEid()));
                        }
                    });
                }
                String dateStr = item.getEuploadtime();
                if (item.getGname() != null && !item.getGname().equals("")) {
                    if (TimeUtils.getGroupStatusTime(dateStr).contains("HH")) {
                        //时间显示有问题出现字母用此方法显示时间
                        item_tt.setText(TimeUtils.getUpLoadTime(dateStr) + context.getResources().getString(R.string.user_item_title1) + item.getGname() + context.getResources().getString(R.string.user_item_title2));
                    } else {
                        item_tt.setText(TimeUtils.getGroupStatusTime(dateStr) + context.getResources().getString(R.string.user_item_title1) + item.getGname() + context.getResources().getString(R.string.user_item_title2));
                    }
                } else {
                    if (TimeUtils.getGroupStatusTime(dateStr).contains("HH")) {
                        item_tt.setText(TimeUtils.getUpLoadTime(dateStr));
                    } else {
                        item_tt.setText(TimeUtils.getGroupStatusTime(dateStr));
                    }
                }
                item_comment_num.setText(StringUtils.numberToStr((item.getComments() == null || item.getComments().size() == 0) ? 0 : item.getComments().size()));
                ll_status_comment.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (!isInAlbum) {
                            return;
                        }
                        if (item.getEtype() == 1) {
                            YNSingleton.getInstance().setCurStatus(item);
                            Intent intent = new Intent(context, MemoryCardDetailCommentActivity.class);
                            context.startActivity(intent);
                        } else {
                            YNSingleton.getInstance().setCurStatus(item);
                            Intent intent = new Intent(context, StatusDetailActivity.class);
                            context.startActivity(intent);
                        }
                    }
                });
                tv_timecard_comment_number.setText(StringUtils.numberToStr((item.getComments() == null || item.getComments().size() == 0) ? 0 : item.getComments().size()));
                item_timecard_comment.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        YNSingleton.getInstance().setCurStatus(item);
                        Intent intent = new Intent(context, MemoryCardDetailCommentActivity.class);
                        intent.putExtra("timeCard", "timeCard");
                        context.startActivity(intent);
                    }
                });
                try {
                    Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).parse(dateStr);
                    String InMouth = DateFormat.format("MM", date).toString();
                    String Indd = DateFormat.format("dd", date).toString();
                    String dateItem = InMouth + "-" + Indd;
                    datemap.put(position, dateItem);
                    if (position == 0) {
                        view_time_day.setText(dateItem);
                    } else {
                        if (TextUtils.equals(dateItem, datemap.get(position - 1))) {
                            view_time_day.setVisibility(View.INVISIBLE);
                        } else {
                            view_time_day.setVisibility(View.VISIBLE);
                            view_time_day.setText(dateItem);
                        }
                    }

//                    if (InYear % 2 == 0) {
//                        view_time.setBackgroundColor(context.getResources().getColor(R.color.user_color_green));
//                        line1.setBackgroundColor(context.getResources().getColor(R.color.user_color_green));
//                        line2.setBackgroundColor(context.getResources().getColor(R.color.user_color_green));
//                    } else {
//                        view_time.setBackgroundColor(context.getResources().getColor(R.color.user_color_yellow));
//                        line1.setBackgroundColor(context.getResources().getColor(R.color.user_color_yellow));
//                        line2.setBackgroundColor(context.getResources().getColor(R.color.user_color_yellow));
//                    }
//                    if (datemap.get(position) == null) {
//                        if (nowyytime != 0 && yytime >= nowyytime) {
//                            view_time.setVisibility(View.INVISIBLE);
//                            datemap.put(position, false);
//                        } else {
//                            view_time.setVisibility(View.VISIBLE);
//                            datemap.put(position, true);
//                        }
//                    } else {
//                        if (datemap.get(position)) {
//                            view_time.setVisibility(View.VISIBLE);
//                        } else {
//                            view_time.setVisibility(View.INVISIBLE);
//                        }
//                    }
//                    if (yearmap.get(position) == null) {
//                        if (nowyear != 0 && InYear >= nowyear) {
//                            yearmap.put(position, false);
//                        } else {
//                            yearmap.put(position, true);
//                            if (InYear % 2 == 0) {
//                                line1.setBackgroundColor(context.getResources().getColor(R.color.user_color_yellow));
//                            } else {
//                                line1.setBackgroundColor(context.getResources().getColor(R.color.user_color_green));
//                            }
//                        }
//                    } else {
//                        if (yearmap.get(position)) {
//                            if (InYear % 2 == 0) {
//                                line1.setBackgroundColor(context.getResources().getColor(R.color.user_color_yellow));
//                            } else {
//                                line1.setBackgroundColor(context.getResources().getColor(R.color.user_color_green));
//                            }
//                        }
//                    }
//                    nowyear = InYear;
//                    nowyytime = yytime;
                } catch (ParseException e) {
                    e.printStackTrace();
                }
//                if (position == 0)
//                    line1.setBackgroundColor(context.getResources().getColor(R.color.transparent));
            }
        }
    }

    private List<String> getUrlList(List<String> sslist) {
        List<String> sslist2 = new ArrayList<>();
        sslist2.clear();
        if (sslist.size() >= 3) {
            for (int i = 0; i < 3; i++) {
                sslist2.add(sslist.get(i));
            }
        } else {
            sslist2 = sslist;
        }
        return sslist2;
    }

    private YNStatus getItem(int position) {
        return mDatas.get(position);
    }

    // 创建ViewHolder
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == EMPTY_VIEW) {
            if (aIsMe) {
                int resId = R.layout.yn_empty_isme_status;
                View v = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
                v.getRootView().getLayoutParams().height = DisplayUtils.getScreenHeightPixels((Activity) context) - DisplayUtils.dp2px(context, 210);
                return new EmptyViewHolder(v);
            } else {
                int resId = R.layout.yn_empty_user_status;
                View v = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
                v.getRootView().getLayoutParams().height = DisplayUtils.getScreenHeightPixels((Activity) context) - DisplayUtils.dp2px(context, 210);
                return new EmptyViewHolder(v);
            }
        }
        final View convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.yn_include_user_album_status_item, parent, false);
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.OnItemClick(v, (YNStatus) convertView.getTag());
                }
            }
        });
        return new ViewHolder(convertView);
    }

    // 绑定数据到View
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder rv_holder, final int position) {
        if (rv_holder instanceof ViewHolder) {
            final ViewHolder holder = (ViewHolder) rv_holder;
            holder.setIsRecyclable(false);
            final YNStatus item = getItem(position);
            holder.bindData(item, position);
            holder.itemView.setTag(item);
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (mDatas.size() == 0) {
            return EMPTY_VIEW;
        }
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return mDatas.size() > 0 ? mDatas.size() : 1;
    }

    public void addItemsFromTop(List<YNStatus> items) {
        if (items == null)
            return;
        this.mDatas.addAll(0, items);
        this.notifyItemRangeInserted(0, items.size());
    }

    public void addItemsFromTopOne(YNStatus items) {
        if (items == null)
            return;
        this.mDatas.add(0, items);
        this.notifyItemRangeInserted(0, 1);
    }

    public void removeOne(int ids) {
        for (int i = 0; i < mDatas.size(); i++) {
            if (ids == mDatas.get(i).getEid()) {
                this.mDatas.remove(i);
                this.notifyItemRemoved(i);
                break;
            }
        }
    }

    public void update(List<YNStatus> mDatas) {
        this.mDatas = mDatas;
    }

    public void SyncComment() {
        for (int i = 0; i < mDatas.size(); i++) {
            if (mDatas.get(i).getEid() == YNSingleton.getInstance().getCurStatus().getEid()) {
                mDatas.get(i).setComments(YNSingleton.getInstance().getCurStatus().getComments());
                UesrAlbumStatusAdapter.this.notifyDataSetChanged();
            }
        }
    }

    public void addItemsFromBottom(List<YNStatus> items) {
        if (items == null)
            return;
        this.mDatas.addAll(mDatas.size(), items);
        this.notifyItemRangeInserted(mDatas.size(), items.size());
    }

    public interface OnItemClickListener {
        public void OnItemClick(View view, YNStatus data);
    }

    public int getIdByDirection(boolean isTop) {
        if (isTop) {
            if (mDatas.size() <= 0) {
                return 0;
            }
            return mDatas.get(0).getEid();
        } else {
            if (mDatas.size() <= 0) {
                return 0;
            }
            return mDatas.get(mDatas.size() - 1).getEid();
        }
    }
}
